package com.CNMedical.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.diboot.core.binding.Binder;
import com.diboot.core.service.impl.BaseServiceImpl;
import com.CNMedical.common.utils.DateUtils;
import com.CNMedical.system.domain.vo.AppletQuestionVO;
import org.springframework.stereotype.Service;
import com.CNMedical.system.mapper.AppletQuestionMapper;
import com.CNMedical.system.domain.entity.AppletQuestion;
import com.CNMedical.system.service.IAppletQuestionService;

import javax.annotation.Resource;

/**
 * 试题Service业务层处理
 * 
 * @author tang
 * @date 2023-03-28
 */
@Service
public class AppletQuestionServiceImpl extends BaseServiceImpl<AppletQuestionMapper, AppletQuestion> implements IAppletQuestionService
{
    @Resource
    private AppletQuestionMapper appletQuestionMapper;

    @Override
    public List<AppletQuestionVO> getAllQuestionByKnowledgeId(String knowledgeId) {
        List<AppletQuestionVO> viewObjectList = this.getViewObjectList(
                Wrappers.lambdaQuery(AppletQuestion.class)
                        .eq(AppletQuestion::getKnowledgeId, knowledgeId)
                , null
                , AppletQuestionVO.class);
        return viewObjectList;
    }

    /**
     * 查询试题
     * 
     * @param id 试题主键
     * @return 试题
     */
    @Override
    public AppletQuestion selectAppletQuestionById(Long id)
    {
        return appletQuestionMapper.selectAppletQuestionById(id);
    }

    /**
     * 查询试题列表
     * 
     * @param appletQuestion 试题
     * @return 试题
     */
    @Override
    public List<AppletQuestionVO> selectAppletQuestionList(AppletQuestion appletQuestion)
    {
        List<AppletQuestion> appletQuestions = appletQuestionMapper.selectAppletQuestionList(appletQuestion);
        List<AppletQuestionVO> appletQuestionVOS = Binder.convertAndBindRelations(appletQuestions, AppletQuestionVO.class);
        return appletQuestionVOS;
    }

    /**
     * 新增试题
     * 
     * @param appletQuestion 试题
     * @return 结果
     */
    @Override
    public int insertAppletQuestion(AppletQuestion appletQuestion)
    {
        appletQuestion.setCreateTime(DateUtils.getNowDate());
        return appletQuestionMapper.insertAppletQuestion(appletQuestion);
    }

    /**
     * 修改试题
     * 
     * @param appletQuestion 试题
     * @return 结果
     */
    @Override
    public int updateAppletQuestion(AppletQuestion appletQuestion)
    {
        appletQuestion.setUpdateTime(DateUtils.getNowDate());
        return appletQuestionMapper.updateAppletQuestion(appletQuestion);
    }

    /**
     * 批量删除试题
     * 
     * @param ids 需要删除的试题主键
     * @return 结果
     */
    @Override
    public int deleteAppletQuestionByIds(Long[] ids)
    {
        return appletQuestionMapper.deleteAppletQuestionByIds(ids);
    }

    /**
     * 删除试题信息
     * 
     * @param id 试题主键
     * @return 结果
     */
    @Override
    public int deleteAppletQuestionById(Long id)
    {
        return appletQuestionMapper.deleteAppletQuestionById(id);
    }
}
